package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {
    public static void main(String[] args) {
        FileInputStream f = null;
        FileOutputStream f2 = null;
        try {
            f = new FileInputStream("C:/Users/86156/Desktop/Snipaste_2024-10-27_16-58-31.png");
            f2 = new FileOutputStream("yuanzhikong.png");
            int t;
            byte[] bytes = new byte[1024];

            while ((t = f.read(bytes)) != -1) {
                f2.write(bytes);
            }

        } catch (IOException e) {

        } finally {
            if (f != null) {
                try {
                    f.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (f2 != null) {
                try {
                    f2.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }

    }
}
